@using Orchard.Roles.Constants
@using Orchard.Roles.ViewModels
@using System.Linq

@model UserRolesViewModel

@{
    Style.Require("FontAwesome");
}

<fieldset>
    <legend>@T("Roles")</legend>

    @if (Model.Roles.Count > 0)
    {
        var index = 0;
        foreach (var entry in Model.Roles)
        {
            if (SystemRoles.GetSystemRoles().Contains(entry.Name))
            {
                continue;
            }

            @Html.Hidden("Roles[" + index + "].RoleId", entry.RoleId)
            @Html.Hidden("Roles[" + index + "].Name", entry.Name)

            <div>
                @if (Model.AuthorizedRoleIds.Contains(entry.RoleId))
                {
                    @Html.CheckBox("Roles[" + index + "].Granted", entry.Granted)
                }
                else
                {
                    @Html.CheckBox("Roles[" + index + "].Granted", entry.Granted, new { disabled = true })
                }
                <label class="forcheckbox" for="@Html.FieldIdFor(m => m.Roles[index].Granted)">@entry.Name</label>
                @if (entry.HasSecurityCriticalPermissions)
                {
                    <i class="fa-solid fa-triangle-exclamation" style="color: red" title="@T("This role contains security critical permissions.")"></i>
                }
            </div>

            index++;
        }
    }
    else
    {
        <p>@T("There are no roles.")</p>
    }
</fieldset>
